﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business;
using ZLCMS.Data.Model;
using System.Text;
using System.Collections;
using NHibernate.Criterion;
using ZLCMS.Business.DwzFrame;
using System.Reflection;
using NHibernate;
using ZLCMS.Business.Util;


namespace ZLCMS.Web.SystemManage.Basics
{
    public partial class TypeTreeIntrodues : System.Web.UI.Page
    {
        FrameHelper _TypeTreeIntrodues;
        public string _userAccount;
        protected CmsTreeDef _TreeDef;
        protected void Page_Load(object sender, EventArgs e)
        {
            _TypeTreeIntrodues = new FrameHelper(this);
            string kindid = Request["tid"];
            if (!IsPostBack)
            {
                using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
                {



                    if (!string.IsNullOrEmpty(kindid))
                    {
                       Image_open.Config = new Business.UploadFileInfo.UploadConfig()
                            {
                                Thumbnail = new ThumbnailConfig()
                                {
                                    Mode = "HW",
                                    Auto = true,
                                    Name = "thumb",
                                    Height = 300,
                                    Width = 300
                                },
                                UploadDir = "treefiel/"
                            };
                        CmsTreeDef doc = session.Get<CmsTreeDef>(Int32.Parse(Request["tid"]));

                        yincangkindid.Text = kindid;
                        txtIntroduces.Value = doc.Memo;

                        //Image_open.Value = FileKit.FirstFileInfo(doc.ImgUrl).ToString();
                        Image_open.Value = doc.ImgUrl;
                        //Image_open.Value = FileKit.FirstFilePath(doc.ImgUrl).ToString();
                      



                    }


                }
            }
            else
            {
                IntroducesSave();
            }
        }

        private void IntroducesSave()
        {
            using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                string id = yincangkindid.Text;
                _TreeDef = session.Get<CmsTreeDef>(int.Parse(id));
                _TreeDef.Memo = txtIntroduces.Value;
                _TreeDef.ImgUrl = Image_open.Value;
                session.Update(_TreeDef);
                session.Flush();
            }

            _TypeTreeIntrodues.Alert(new ReturnCode()
            {
                statusCode = 200,
                message = "操作成功!",
                navTabId = _TypeTreeIntrodues.NavTabId
            });
        }

        //protected void InitializeGlobalValue()
        //{
        //    using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
        //    {
        //        try
        //        {
        //            if (!IsPostBack)
        //            {
        //                _id.Text = Request["uid"];
        //            }

        //            _recrDb = session.Get<RecruitmentInfo>(int.Parse(_id.Text));

        //            //CmsTreeDef node = null;
        //            //if (_recrDb.TypeId != 0)
        //            //{
        //            //    node = session.Get<CmsTreeDef>((int)_recrDb.TypeId);
        //            //}
        //            //if (node != null)
        //            //{
        //            //    ddTreeControl.SelectedNodeId = node.Id;
        //            //    ddTreeControl.SelectedNodeText = node.Name;
        //            //}

        //            if (_recrDb == null)
        //            {
        //                throw new Exception("找不到对应信息.");
        //            }

        //        }
        //        catch (System.Exception ex)
        //        {
        //            _frameHelper.Alert(new ReturnCode() { statusCode = 300, message = "操作出错-" + ex.Message });
        //            return;
        //        }
        //    }
        //}

        //protected void InitializeContent()
        //{
        //    //页面控件值
        //    if (!IsPostBack)
        //    {
        //        ParamKit.Bind("WorkPos", ddl_pos, null, new List<ListItem>() { ParamKit.ParamItemEx_QXZ() }, null, "-1", "-1");
        //        ParamKit.Bind("WorkCity", ddl_addr, null, new List<ListItem>() { ParamKit.ParamItemEx_QXZ() }, null, "-1", "-1");

        //        tb_title.Text = _recrDb.Title;
        //        ddl_addr.SelectedValue = _recrDb.WorkAddr;
        //        ddl_pos.SelectedValue = _recrDb.WorkPost;
        //        tb_expiry.Text = _recrDb.ExpiryDate.ToString("yyyy-MM-dd");
        //        tb_reqnum.Text = _recrDb.RequstNum.ToString();
        //        tb_order.Text = _recrDb.ShowOrder.ToString();
        //        txt_xx.Value = _recrDb.Content;
        //    }
        //}
    }
}
